package com.juphoon.mockdata.data.dto;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
public class E06SysHead {
    @JacksonXmlProperty(localName = "SERVICE_CODE")
    @JsonProperty("SERVICE_CODE")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String serviceCode;

    @JacksonXmlProperty(localName = "SERVICE_SCENE")
    @JsonProperty("SERVICE_SCENE")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String serviceScene;

    @JacksonXmlProperty(localName = "SERVICE_VERSION")
    @JsonProperty("SERVICE_VERSION")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String serviceVersion;

    @JacksonXmlProperty(localName = "CONSUMER_ID")
    @JsonProperty("CONSUMER_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String consumerId;

    @JacksonXmlProperty(localName = "TRAN_TIMESTAMP")
    @JsonProperty("TRAN_TIMESTAMP")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String tranTimestamp;

    @JacksonXmlProperty(localName = "LEGAL_ENTITY_CODE")
    @JsonProperty("LEGAL_ENTITY_CODE")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String legalEntityCode;

    @JacksonXmlProperty(localName = "TRAN_DATE")
    @JsonProperty("TRAN_DATE")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String tranDate;

    @JacksonXmlProperty(localName = "SOURCE_BRANCH_NO")
    @JsonProperty("SOURCE_BRANCH_NO")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String sourceBranchNo;

    @JacksonXmlProperty(localName = "BRANCH_ID")
    @JsonProperty("BRANCH_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String branchId;

    @JacksonXmlProperty(localName = "CONSUMER_SEQ_NO")
    @JsonProperty("CONSUMER_SEQ_NO")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String consumerSeqNo;

    @JacksonXmlProperty(localName = "TRACE_ID")
    @JsonProperty("TRACE_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String traceId;

    @JacksonXmlProperty(localName = "USER_ID")
    @JsonProperty("USER_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String userId;

    @JacksonXmlProperty(localName = "WS_ID")
    @JsonProperty("WS_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String wsId;

    @JacksonXmlProperty(localName = "ORG_SYS_ID")
    @JsonProperty("ORG_SYS_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String orgSysId;

    @JacksonXmlProperty(localName = "MODULE_ID")
    @JsonProperty("MODULE_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String moduleId;

    @JacksonXmlProperty(localName = "AUTH_USER_ID")
    @JsonProperty("AUTH_USER_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String authUserId;

    @JacksonXmlProperty(localName = "AUTH_PASSWORD")
    @JsonProperty("AUTH_PASSWORD")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String authPassword;

    @JacksonXmlProperty(localName = "ISSUE_OBJECT")
    @JsonProperty("ISSUE_OBJECT")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String issueObject;

    @JacksonXmlProperty(localName = "AUTH_FLAG")
    @JsonProperty("AUTH_FLAG")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String authFlag;

    @JacksonXmlProperty(localName = "APPR_FLAG")
    @JsonProperty("APPR_FLAG")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String apprFlag;

    @JacksonXmlProperty(localName = "SSO_USER_ID")
    @JsonProperty("SSO_USER_ID")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String ssoUserId;

    @JacksonXmlProperty(localName = "SOURCE_TYPE")
    @JsonProperty("SOURCE_TYPE")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String sourceType;

    @JacksonXmlProperty(localName = "CONSUMER_TRAN_CODE")
    @JsonProperty("CONSUMER_TRAN_CODE")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String consumerTranCode;

    @Data
    public static class Request extends E06SysHead {

        @JacksonXmlElementWrapper(localName = "AUTH_USER_ID_ARRAY")
        @JacksonXmlProperty(localName = "struct")
        @JsonInclude(JsonInclude.Include.NON_NULL)
        private List<AuthUser> authUsers;

        @Data
        @Builder
        @NoArgsConstructor
        @AllArgsConstructor
        public static class AuthUser {
            @JacksonXmlProperty(localName = "AUTH_USER_ID")
            private String authUserId;

            @JacksonXmlProperty(localName = "AUTH_PASSWORD")
            private String authPassword;

            @JacksonXmlProperty(localName = "AUTH_USER_SSO_USER_ID")
            private String authUserSsoUserId;

            @JacksonXmlProperty(localName = "AUTH_LEVEL")
            private String authLevel;

            @JacksonXmlProperty(localName = "AUTH_TYPE")
            private String authType;

        }

    }

    @Data
    public static class Response extends E06SysHead {

        @JacksonXmlElementWrapper(localName = "RET")
        @JacksonXmlProperty(localName = "struct")
        @JsonProperty("RET")
        private List<ResultDTO> ret;

        @JacksonXmlElementWrapper(localName = "RET_STATUS")
        @JsonProperty("RET_STATUS")
        private String retStatus;

        @Data
        public static class ResultDTO {
            @JacksonXmlProperty(localName = "RET_CODE")
            @JsonProperty("RET_CODE")
            private String retCode;

            @JacksonXmlProperty(localName = "RET_MSG")
            @JsonProperty("RET_MSG")
            private String retMsg;
        }

        @JsonIgnore
        public boolean isOk() {
            return ret != null && ret.size() > 0 && StrUtil.equals(ret.get(0).getRetCode(), "000000");
        }

    }

}
